#pragma once
#include <windows.h>
#include <string>

/**
* A generic window object.
* @author Koen Samyn
*/
class Window
{
public:
	/**
	* Create a new toplevel window.
	* @param title the title of the top level window.
	*/
	Window(std::wstring title, unsigned int width, unsigned int height);
	/**
	* Destroy the top level window.
	*/
	virtual ~Window(void);
	/**
	* Sets the win32 handle that is associated with the window
	* @param hWnd the handle to the window.
	*/
	void SetHWND(HWND hWnd){
		m_hWnd = hWnd;
	}
	/**
	* Called when the size of the window changes.
	* @param width the new width of the window.
	* @param height the new height of the window.
	*/
	virtual void Resize(unsigned int width, unsigned int height)
	{
		m_Width = width;
		m_Height = height;
	}
	/**
	* Called when the window should be repainted.
	*/
	virtual void Repaint(){}
	/**
	* Sets the visible state of this window.
	* @param visible the visible state of this window.
	*/
	void SetVisible(bool visible);
	/**
	* Checks the visible state of this window.
	* @return true if the window is visible, false otherwise.
	*/
	bool IsVisible(){
		return m_Visible;
	}

	/**
	* Sets the active or inactive state of the program
	* @param active this parameter is true if the program is active, false otherwise.
	*/ 
	void SetActive(bool active){ m_Active = active;}
	/**
	* Checks the active state of the program.
	*/
	bool IsActive(){return m_Active;}
	/**
	* A key pressed event was received.
	* @param key the character that was pressed.
	*/ 
	virtual void KeyPressed(int keyCode){}
	/**
	* A key released event was received.
	* @param key the character that was released.
	*/
	virtual void KeyReleased(int keyCode){}
	/**
	* A keys was typed.
	* @param key the character that was typed.
	*/
	virtual void KeyTyped(wchar_t keyCode){}
	/**
	* The static windows procedure.
	* @param hWnd the handle to the window.
	* @param uMsh the message
	* @param wParam additional message information.
	* @param lParam additional message information.
	*/ 
	static LRESULT CALLBACK WndProc( HWND	hWnd, UINT	uMsg, WPARAM	wParam,	LPARAM	lParam);

	virtual bool Kill(){return true;}
protected:
	/**
	* The title of the toplevel window.
	*/
	std::wstring m_Title;
	/**
	* The width and height of the window.
	*/
	unsigned int m_Width;
	unsigned int m_Height;
	/**
	* Internal method that creates the window.
	*/
	virtual bool Create();
	/**
	* Creates a default window class for this window.
	*/
	virtual bool CreateDefaultWindowClass(WNDCLASSEX& wc);
	/**
	* Creates a window with the specified style.
	* @param dwExStyle the extended style for the window.
	* @param dwStyle the style for the window.
	*/
	virtual bool CreateStyledWindow(DWORD	dwExStyle,DWORD	dwStyle);				
	/**
	* Win32 handles for this Window object.
	*/ 
	HWND		m_hWnd;	
	HINSTANCE	m_hInstance;
	HDC			m_hDC;
	HGLRC		m_hRC;
private:
	/**
	* Active state
	*/
	bool m_Active;
	/**
	* Is the window visible.
	*/
	bool m_Visible;
	/**
	* Was the window created.
	*/
	bool m_Created;
};

